using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using Sirenix.Serialization;

namespace BTEditor
{
    [BTDecorator]
    public class WaitForCondition : Decorator
    {
        public override Type GetNodeType()
        {
            return typeof(NPBehave.WaitForCondition);
        }

        public override ErrorType GetIsVaild()
        {
            if (!BelongNode.IsHaveChild)
            {
                return  ErrorType.Error;
            }
            return Action != null ? ErrorType.None : ErrorType.Error;
        }

        public override int CanAddNodeCount => 0;

        [ValueDropdown("ValuesFunction", DropdownTitle = "方法选择", DropdownHeight = 500,
            DisableListAddButtonBehaviour = true)]
        [HideLabel]
        [Title("方法")]
        [ShowInInspector]
        [BTValue(DealType.ActionToChild)]
        [OdinSerialize]
        public BoolFunc Action;
        
        [HideLabel] [Title("方法执行间隔")] 
        [BTValue(DealType.OnlyUse)]
        [OdinSerialize]
        public float checkInterval;

        [HideLabel] [Title("执行差异")] 
        [BTValue(DealType.OnlyUse)]
        [OdinSerialize]
        public float randomVariance = 0;
    
        private IEnumerable ValuesFunction()
        {
            List<Type> types = GetType().Assembly.GetTypes().ToList();
            return types.Where(x => x.IsSubclassOf(typeof(BoolFunc)))
                .Select(x => Activator.CreateInstance(x))
                .Select(x => new ValueDropdownItem(x.ToString(), x));
        }

    }
}